<?php
namespace jy_qiuyuyue;
defined('BY_JYA') or exit('error');
/*
	订单
*/
class order extends \plugin{
	//确认收货，完成订单
	public function order_receive($order_id,$ismsg=false){
		$update=array('status'=>3,'finishtime'=>TIMESTAMP);
		$this->update('order',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		$this->get_order($order_id);
		$notice_setting=$this->plugin_setting('notice');
		if(!$ismsg){
			$this->model('notice')->notice_receive2buyer($this->order);
			if($notice_setting['seller']){
				foreach($notice_setting['seller'] as $member){
					$this->model('notice')->notice_receive2seller($this->order,$member['mid']);
				}
			}
		}
	}
	public function checktimeid($is_ban,$timeid='',$store_id=0,$day='',$serve_id=0,$plate_id=0,$open_total=0,$total=0){
		$params=array('timeid like'=>'%;'.$timeid.';%','store_id'=>$store_id,'day'=>$day,'serve_id'=>$serve_id,'plate_id'=>$plate_id,'status'=>array(1,2,4));
		$num=pdo_getsum('jy_qiuyuyue_server_order',$params,'total');
		if($open_total){
			$lastnum=$total-$num;
			return $lastnum;
		}
		if($num){
			return false;
		}elseif($is_ban){
			$timekey=substr($timeid, 0, -1).'C';
			$params=array('timeid like'=>'%;'.$timekey.';%','store_id'=>$store_id,'day'=>$day,'serve_id'=>$serve_id,'plate_id'=>$plate_id,'status'=>array(1,2,4));
			$num=pdo_count('jy_qiuyuyue_server_order',$params);
			if($num){
				return false;
			}
		}
		return true;
	}
	public function getnum($timeid='',$store_id=0,$day='',$serve_id=0,$plate_id=0){
		$params=array('timeid like'=>'%;'.$timeid.';%','store_id'=>$store_id,'day'=>$day,'serve_id'=>$serve_id,'plate_id'=>$plate_id,'status'=>array(1,2,4));
		$num=pdo_count('jy_qiuyuyue_server_order',$params);
		return $num;
	}
}